package models

import (
	"time"
)

// 订单物流表
type OrderCourier struct {
	Id               uint       `gorm:"column:id;type:int(11) unsigned;primary_key;AUTO_INCREMENT;comment:主键ID" json:"id"`
	OrderNo          string     `gorm:"column:order_no;type:varchar(100);comment:关联订单号;NOT NULL" json:"order_no"`
	RecipientName    string     `gorm:"column:recipient_name;type:varchar(100);comment:收件人姓名;NOT NULL" json:"recipient_name"`
	RecipientPhone   string     `gorm:"column:recipient_phone;type:varchar(30);comment:收件人电话;NOT NULL" json:"recipient_phone"`
	RecipientCity    string     `gorm:"column:recipient_city;type:varchar(255);comment:所在城市;NOT NULL" json:"recipient_city"`
	RecipientAddress string     `gorm:"column:recipient_address;type:varchar(255);comment:收件人地址;NOT NULL" json:"recipient_address"`
	Courier          string     `gorm:"column:courier;type:varchar(100);comment:物流公司名称;NOT NULL" json:"courier"`
	TrackingNo       string     `gorm:"column:tracking_no;type:varchar(100);comment:快递单号;NOT NULL" json:"tracking_no"`
	ShipTime         *time.Time `gorm:"column:ship_time;type:datetime;comment:发货时间" json:"ship_time"`
	DeliveryTime     *time.Time `gorm:"column:delivery_time;type:datetime;comment:送达时间" json:"delivery_time"`
	Attachments      string     `gorm:"column:attachments;type:json;comment:快递附件（如图片、签收凭证等）" json:"attachments"`
	CourierStatus    int        `gorm:"column:courier_status;type:tinyint(4);default:0;comment:物流状态：0=待发货,1=已发货,2=运输中,3=派送中,4=已签收,5=异常;NOT NULL" json:"courier_status"`
	CreatedTime      time.Time  `gorm:"column:created_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;NOT NULL" json:"created_time"`
	UpdatedTime      time.Time  `gorm:"column:updated_time;type:timestamp;default:CURRENT_TIMESTAMP;comment:更新时间;NOT NULL" json:"updated_time"`
}

func (m *OrderCourier) TableName() string {
	return "order_courier"
}

// 物流状态常量
const (
	CourierStatusPending    = 0 // 待发货
	CourierStatusShipped    = 1 // 已发货
	CourierStatusInTransit  = 2 // 运输中
	CourierStatusDelivering = 3 // 派送中
	CourierStatusDelivered  = 4 // 已签收
	CourierStatusException  = 5 // 异常
)

// 物流状态对应中文描述
var CourierStatusText = map[int]string{
	CourierStatusPending:    "待发货",
	CourierStatusShipped:    "已发货",
	CourierStatusInTransit:  "运输中",
	CourierStatusDelivering: "派送中",
	CourierStatusDelivered:  "已签收",
	CourierStatusException:  "异常",
}
